﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using TodoList.ViewModel;
using TodoList.Mode;
using Microsoft.Win32;
using System.Configuration;
using TodoList.Common;
using TodoList.Properties;

namespace TodoList.Command
{
    class SetCommand : ICommand
    {
        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "Xml files (*.xml)|*.xml";
            bool? bval = fileDialog.ShowDialog();
            bool res = bval ?? false;
            if (!res) return;
            TodoVM vm = parameter as TodoVM;
            vm.FileName = fileDialog.FileName;
            vm.LoadAction.Execute( parameter);
            Utils.SetLastFile(Settings.Default.LastFileItem, vm.FileName);

        }
        #endregion
    }
}
